package com.jishuo.nontax.bfc.service;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.nontax.bean.bank.OnlineOrder;
import com.jishuo.nontax.bean.vo.OnlineOrderList;
import com.jishuo.nontax.bfc.dao.OnlineOrderMapper;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.List;

/**
 * @author hlp
 * @date 2023/12/11 09:37
 * @Description:
 */
@Service
public class OnlineOrderService {
    private static Logger logger = LoggerFactory.getLogger(OnlineOrderService.class);

    @Resource
    private OnlineOrderMapper onlineOrderMapper;

    public int saveOnlineOrder(OnlineOrder oo) {
        if (onlineOrderMapper.findPatInfoOline(oo.getBillnum(), oo.getBilltype()) == null) {
            return onlineOrderMapper.saveOnlineOrder(oo);
        } else {
            return onlineOrderMapper.updateOnlineOrder(oo);
        }
    }

    public BaseResult findPayInfoOnLine(String billnum, int billtype){
        try {
            Serializer serializer = new Persister();
            OnlineOrder patInfoOline = onlineOrderMapper.findPatInfoOline(billnum, billtype);
            if(patInfoOline!=null){
                StringWriter sw = new StringWriter();
                serializer.write(patInfoOline,sw);
                return new BaseResult(sw.toString());
            }else{
                return new BaseResult("01","失败");
            }
        }catch (Exception e){
            logger.info("失败："+e.toString());
            return new BaseResult("01","失败");
        }
    }

    public BaseResult listPayInfoOnLine(String paybankdt){
        try {
            Serializer serializer = new Persister();
            OnlineOrderList olist = new OnlineOrderList();
            List<OnlineOrder> list = onlineOrderMapper.listPayInfoOnline(paybankdt);
            olist.setList(list);
            StringWriter sw = new StringWriter();
            serializer.write(olist,sw);
            return new BaseResult(sw.toString());
        }catch (Exception e){
            logger.info("失败："+e.toString());
            return new BaseResult("01","失败");
        }
    }

    public List<OnlineOrder> queryOnlineOrder(String paybankdt){
        return onlineOrderMapper.listPayInfoOnline(paybankdt);
    }

}
